1 <?php
2 include("../includes/config.php");
3 include("../includes/validate_data.php");
4 session_start();
5 if(isset($_SESSION['manufacturer_login'])) {
6 if($_SESSION['manufacturer_login'] == true) {
7 $id = $_GET['id'];
8 $query_selectProductDetails = "SELECT * FROM products WHERE pro_id='$id'";
9 $result_selectProductDetails = mysqli_query($con,$query_selectProductDetails);
10 $row_selectProductDetails = mysqli_fetch_array($result_selectProductDetails);
11 $query_selectCategory = "SELECT cat_id,cat_name FROM categories";
12 $query_selectUnit = "SELECT id,unit_name FROM unit";
13 $result_selectCategory = mysqli_query($con,$query_selectCategory);
14 $result_selectUnit = mysqli_query($con,$query_selectUnit);
15 $name = $price = $unit = $category = $description = "";
16 $nameErr = $priceErr = $requireErr = $confirmMessage = "";
17 $nameHolder = $priceHolder = $descriptionHolder = "";
18 if($_SERVER['REQUEST_METHOD'] == "POST") {
19 if(!empty($_POST['txtProductName'])) {
20 $nameHolder = $_POST['txtProductName'];
21 $name = $_POST['txtProductName'];
22 }
23 if(!empty($_POST['txtProductPrice'])) {
24 $priceHolder = $_POST['txtProductPrice'];
25 $resultValidate_price = validate_price($_POST['txtProductPrice']);
26 if($resultValidate_price == 1) {
27 $price = $_POST['txtProductPrice'];
28 }
29 else {
30 $priceErr = $resultValidate_price;
31 }
32 }
33 if(isset($_POST['cmbProductUnit'])) {
34 $unit = $_POST['cmbProductUnit'];
35 }
36 if(isset($_POST['cmbProductCategory'])) {
37 $category = $_POST['cmbProductCategory'];
38 }
39 if(empty($_POST['rdbStock'])) {
40 $rdbStock = "";
41 }
42 else {
43 if($_POST['rdbStock'] == 1) {
44 $rdbStock = 1;
45 }
46 else if($_POST['rdbStock'] == 2) {
47 $rdbStock = 2;
48 }
49 }
50 if(!empty($_POST['txtProductDescription'])) {
51 $description = $_POST['txtProductDescription'];
52 $descriptionHolder = $_POST['txtProductDescription'];
53 }
54 if($name != null && $price != null && $unit != null && $category != null && $rdbStock == 1) {
55 $rdbStock = 0;
56 $query_UpdateProduct = "UPDATE products SET pro_name='$name',pro_desc='$description',pro_price='$price',unit='$unit',pro_cat='$category',quantity='$rdbStock' WHERE pro_id='$id'";
57 if(mysqli_query($con,$query_UpdateProduct)) {
58 echo "<script> alert(\"Product Updated Successfully\"); </script>";
59 header('Refresh:0;url=view_products.php');
60 }
61 else {
62 $requireErr = "Updating Product Failed";
63 }
64 }
65 else if($name != null && $price != null && $unit != null && $category != null && $rdbStock == 2) {
66 $query_UpdateProduct = "UPDATE products SET pro_name='$name',pro_desc='$description',pro_price='$price',unit='$unit',pro_cat='$category',quantity=NULL WHERE pro_id='$id'";
67 if(mysqli_query($con,$query_UpdateProduct)) {
68 echo "<script> alert(\"Product Updated Successfully\"); </script>";
69 header('Refresh:0');
70 }
71 else {
72 $requireErr = "Updating Product Failed";
73 }
74 }
75 else {
76 $requireErr = "* All Fields are Compulsory with valid values except Description";
77 }
78 }
79 }
80 else {
81 header('Location:../index.php');
82 }
83 }
84 else {
85 header('Location:../index.php');
86 }
87 ?>
88 <!DOCTYPE html>
89 <html>
90 <head>
91 <title> Add Product </title>
92 <link rel="stylesheet" href="../includes/main_style.css" >
93 </head>
94 <body>
95 <?php
96 include("../includes/header.inc.php");
97 include("../includes/nav_manufacturer.inc.php");
98 include("../includes/aside_manufacturer.inc.php");
99 ?>
100 <section>
101 <h1>Edit Product</h1>
102 <form action="" method="POST" class="form">
103 <ul class="form-list">
104 <li>
105 <div class="label-block"> <label for="product:name">Product Name</label> </div>
106 <div class="input-box"> <input type="text" id="product:name" name="txtProductName" placeholder="Product Name" value="<?php echo $row_selectProductDetails['pro_name']; ?>" required /> </div> <span class="error_message"><?php echo $nameErr; ?></span>
107 </li>
108 <li>
109 <div class="label-block"> <label for="product:price">Price</label> </div>
110 <div class="input-box"> <input type="text" id="product:price" name="txtProductPrice" placeholder="Price" value="<?php echo $row_selectProductDetails['pro_price']; ?>" required /> </div> <span class="error_message"><?php echo $priceErr; ?></span>
111 </li>
112 <li>
113 <div class="label-block"> <label for="product:unit">Unit Type</label> </div>
114 <div class="input-box">
115 <select name="cmbProductUnit" id="product:unit">
116 <option value="" disabled selected>--- Select Unit ---</option>
117 <?php while($row_selectUnit = mysqli_fetch_array($result_selectUnit)) { ?>
118 <option value="<?php echo $row_selectUnit["id"]; ?>" <?php if($row_selectProductDetails['unit'] == $row_selectUnit["id"]){echo "selected";} ?>> <?php echo $row_selectUnit["unit_name"]; ?> </option>
119 <?php } ?>
120 </select>
121 </div>
122 </li>
123 <li>
124 <div class="label-block"> <label for="product:category">Category</label> </div>
125 <div class="input-box">
126 <select name="cmbProductCategory" id="product:category">
127 <option value="" disabled selected>--- Select Category ---</option>
128 <?php while($row_selectCategory = mysqli_fetch_array($result_selectCategory)) { ?>
129 <option value="<?php echo $row_selectCategory["cat_id"]; ?>" <?php if($row_selectProductDetails['pro_cat'] == $row_selectCategory["cat_id"]){echo "selected";} ?>> <?php echo $row_selectCategory["cat_name"]; ?> </option>
130 <?php } ?>
131 </select>
132 </div>
133 </li>
134 <li>
135 <div class="label-block"> <label for="product:stock">Stock Management</label> </div>
136 <input type="radio" name="rdbStock" value="1">Enable
137 <input type="radio" name="rdbStock" value="2">Disable
138 </li>
139 <li>
140 <div class="label-block"> <label for="product:description">Description</label> </div>
141 <div class="input-box"> <textarea type="text" id="product:description" name="txtProductDescription" placeholder="Description"><?php echo $row_selectProductDetails['pro_desc']; ?></textarea> </div>
142 </li>
143 <li>
144 <input type="submit" value="Update Product" class="submit_button" /> <span class="error_message"> <?php echo $requireErr; ?> </span><span class="confirm_message"> <?php echo $confirmMessage; ?> </span>
145 </li>
146 </ul>
147 </form>
148 </section>
149 <?php
150 include("../includes/footer.inc.php");
151 ?>
152 </body>
153 </html>